<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<include file="public@head" title="邮箱设置" keywords="后台管理系统" />
		<link href="__STATIC__/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
	</head>

	<body>
		<div class="layui-tab">
			<ul class="layui-tab-title">
				<li>
					<a href="{:url('admin/mailer/index')}">邮箱设置</a>
				</li>
				<li class="layui-this">
					<a href="{:url('admin/mailer/template')}">邮件模板</a>
				</li>
			</ul>
		</div>
		<form method="post" class="layui-form layui-col-md6 padding-top-10" role="form" action="{:url('admin/mailer/template')}">
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="form-required">*</span>邮件主题</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input" lay-verify="required" name="subject" value="{$subject|default=''}">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">邮件模板</label>
				<div class="layui-input-block">
					<script type="text/plain" id="content" name="template" style="width:100%;height:240px;">
						{$template|default=""|htmlspecialchars_decode}
					</script>
					<literal><span style="color: #ffb752;">请用{$code}代替数字验证码，{$username}代替用户名</span></literal>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="hidden" name="template_key" value="order">
					<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="save">保存</button>
				</div>
			</div>
		</form>

		<script src="__STATIC__/layui/layui.all.js"></script>
		<script>
			var element = layui.element,
				form = layui.form,
				$ = layui.jquery,
				jQuery = layui.jquery,
				layer = layui.layer;
		</script>
		<script type="text/javascript" src="__STATIC__/umeditor/third-party/template.min.js"></script>
		<script type="text/javascript" charset="utf-8" src="__STATIC__/umeditor/umeditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="__STATIC__/umeditor/umeditor.min.js"></script>
		<script type="text/javascript" src="__STATIC__/umeditor/lang/zh-cn/zh-cn.js"></script>
		<script>
			var um = UM.getEditor('content', {
				toolbar: [
					'source | bold italic underline | emotion image video | forecolor backcolor | removeformat |',
					'insertorderedlist | cleardoc paragraph | fontsize',
					'| justifyleft justifycenter justifyright justifyjustify |',
					'link unlink | horizontal preview fullscreen', 'drafts',
				]
			});

			form.on('submit(save)', function(data) {
				$.post("{:url('admin/mailer/template')}", data.field, function(res) {
					if(res.code == 1) {
						layer.msg(res.msg, {
							icon: 6
						}, function() {
							window.location.href = res.url;
						});
					} else {
						layer.msg(res.msg, {
							icon: 5
						}, function() {
							return false;
						});
					}
				});
				return false;
			});
		</script>
	</body>

</html>